package com.construction.api.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Objects;

/**
 * @author dybin
 * @Date: 2021/7/1 22:00
 */
@Getter
@AllArgsConstructor
public enum ResultEnum {

    /**
     * success
     */
    SUCCESS(0, "Success"),

    /**
     * 无效请求
     */
    BAD_REQUEST(400, "Bad Request"),

    /**
     * Unauthorized
     */
    UNAUTHORIZED(401, "Unauthorized"),

    /**
     * Forbidden
     */
    FORBIDDEN(403, "Forbidden"),

    /**
     * Not Found
     */
    NOT_FOUND(404, "Not Found"),

    /**
     * token expired
     */
    TOKEN_EXPIRED(501, "Token Expired"),

    /**
     * business error
     */
    BUSINESS_UNUSUAL(500, "Business Error");

    private final Integer code;
    private final String msg;

    public static ResultEnum of(Integer status) {
        return Arrays.stream(ResultEnum.values()).filter(it -> Objects.equals(it.getCode(), status)).findFirst().orElse(null);
    }
}
